package config

import (
	"strings"
	"github.com/ngaut/log"
)

type logConfig struct {
	On     bool   `toml:"log_on"`
	Dir    string `toml:"log_dir"`
	File   string `toml:"log_file"`
	Level  string `toml:"log_level"`
	Rotate string `toml:"log_rotate"`
}

// 获取文件名
func (l logConfig) getFilePath() string {
	path := strings.TrimRight(l.Dir, "/")
	file := l.File
	if file == "" {
		file = "bitkop.log"
	}
	return path + "/" + file
}

func (l logConfig) Setting() {
	filePath := l.getFilePath()
	if l.On && filePath != "" {
		log.SetOutputByName(filePath)
		log.SetLevelByString(l.Level)
		if l.Rotate == "H" || l.Rotate == "" {
			log.SetRotateByHour()
		} else {
			log.SetRotateByDay()
		}
		log.SetHighlighting(false)
	}
}